﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<div ng-controller="EditableRowCtrl" class="district-page">
    <label>Location</label>
    <select class="form-control" ng-model="myLocation" ng-options="location.name for location in locations"
            ng-change="locationChanged()"></select>
    <br/>
    <button class="btn btn-default" ng-click="addDistrict()">Add New District</button>
    <table class="table table-bordered table-hover table-condensed">
        <tr style="font-weight: bold">
            <td style="width: 75%">Name</td>
            <td style="width: 25%">Action</td>
        </tr>
        <tr ng-repeat="district in districts">
            <td>
                <!-- editable (text with validation) -->
                <span editable-text="district.name" e-name="name" e-form="rowform" onbeforesave="checkName($data, district.id)" e-required>{{ district.name || 'empty' }}
                </span>
            </td>
            <td style="white-space: nowrap">
                <!-- form -->
                <form editable-form name="rowform" onbeforesave="saveDistrict($data, district.id)" ng-show="rowform.$visible" class="form-buttons form-inline" shown="inserted == district">
                    <button type="submit" ng-disabled="rowform.$waiting" class="btn btn-primary">
                        Save
                    </button>
                    <button type="button" ng-disabled="rowform.$waiting" ng-click="rowform.$cancel()" class="btn btn-default">
                        Cancel
                    </button>
                </form>
                <div class="buttons" ng-show="!rowform.$visible">
                    <button class="btn btn-primary" ng-click="rowform.$show()">Edit</button>
                    <button class="btn btn-danger" data-toggle="modal" data-target="#myModal-{{$index}}">Delete</button>
                </div>
                <div class="modal fade" id="myModal-{{$index}}">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                <h4 class="modal-title">Confirm</h4>
                            </div>
                            <div class="modal-body">
                                <p>Are you sure to delete?</p>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal">No</button>
                                <button type="button" class="btn btn-primary" ng-click="removeDistrict($index)">Yes</button>
                            </div>
                        </div>
                        <!-- /.modal-content -->
                    </div>
                    <!-- /.modal-dialog -->
                </div>
            </td>
        </tr>
    </table>

    <button class="btn btn-default" ng-click="addDistrict()">Add New District</button>

</div>
@section scripts{
    <script type="text/javascript" src="/Scripts/app/district.js"></script>
}